﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - ClassroomBorrow" 
*/ 

component 
	displayname="public.service.db.senate.sequence.ClassroomBorrow" 
	output=false 
	accessors=true 
	{
		
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = dateFormat(now(), "YYYYMMDD") & numberFormat(1, "0_____");
		
		/* 
			主键生成规则 CHAR(14)
			
			8位日期 6位为流水号
		*/
		var sql = "SELECT cbr_id FROM t_clsroom_borrow 
					WHERE 
						cbr_id LIKE :condition 
					ORDER BY cbr_id DESC ";
		
		var queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		
		queryObj.addParam( name="condition", value=dateFormat(now(), "YYYYMMDD") & "______", cfsqltype="cf_sql_char" );

		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		if ( rs_check.recordCount ) {
			/* 创建一个追加id */
			nextID = DateFormat(now(), "YYYYMMDD") & numberFormat( ( right( rs_check.cbr_id, 6 ) + 1 ), "0_____" );
		}

		return nextID;
	}
	
}

</cfscript>